/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.p10.miage.gestionnote.modelservice;

import fr.p10.miage.gestionabsence.model.Connection;
import fr.p10.miage.gestionnote.model.Ec;
import fr.p10.miage.gestionnote.model.Ue;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author mehdibeggas
 */
public class UeServices extends UtilService
{
    
    private static Connection cx;
    
    public static List<Ec> getEcs(int idPromotion,int idF,int idue,int idEtudiant) throws SQLException
    {
        List<Ec> listeEcs = new ArrayList<Ec>();

        String sql = "SELECT e.idec, e.nom, e.code, ecue.coeff, ecue.nbrtd,ecue.nbrcm\n" +
                    "FROM ec e, ue u, ec_ue ecue\n" +
                    "WHERE ecue.idue = u.idue\n" +
                    "AND ecue.idec = e.idec\n" +
                    "AND ecue.idue= "+idue+"\n" +
                    "AND ecue.idf= "+idF+"";

        PreparedStatement pst = cx.getBDD().prepareStatement(sql);

        if (pst.execute()) {
            ResultSet resultat = pst.getResultSet();
            while (resultat.next()) {
               // AJouter l'idPromotion
                listeEcs.add(new Ec(
                        resultat.getInt("idec"),
                        idF,
                        idPromotion,
                        idue,
                        resultat.getString("nom"),
                        resultat.getString("code"),
                        resultat.getFloat("coeff"),
                        resultat.getInt("nbrtd"),
                        resultat.getInt("nbrcm"),
                        idEtudiant
                        ));
            }
            resultat.close();
        }

        pst.close();
        return listeEcs;
    }
    
    public static Ue getUeById()
    {
        return null;
    }
    
}
